#https://leetcode.cn/problems/max-consecutive-ones-iii/solutions/2126631/hua-dong-chuang-kou-yi-ge-shi-pin-jiang-yowmi/

class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int ans = 0, i = 0, cnt = 0;
        for (int j = 0; j < nums.size(); j++) {
            cnt += 1 - nums[j];
            while (cnt > k) {
                cnt -= 1 - nums[i++];
            }
            ans = max(ans, j - i + 1);
        }
        return ans;
    }
};
